<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>教师管理中心 - 在线考试系统</title>
    <div th:replace="include/bootstrap :: bootstrap"></div>
    <style>
        .stats-card {
            background: white;
            border-radius: 8px;
            padding: 25px;
            margin-bottom: 30px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
            transition: all 0.3s ease;
            height: 100%;
        }
        .stats-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        }
        .stats-icon {
            font-size: 40px;
            margin-bottom: 20px;
            color: #3498db;
        }
        .stats-number {
            font-size: 24px;
            font-weight: 700;
            color: #2c3e50;
            margin-bottom: 5px;
        }
        .stats-title {
            color: #7f8c8d;
            font-size: 16px;
            margin-bottom: 0;
        }
        .welcome-card {
            background: linear-gradient(135deg, #3498db, #2c3e50);
            color: white;
            border-radius: 8px;
            padding: 30px;
            margin-bottom: 30px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
        }
        .welcome-card h2 {
            font-weight: 700;
            margin-bottom: 15px;
        }
        .welcome-card p {
            opacity: 0.9;
            margin-bottom: 20px;
            line-height: 1.6;
        }
        .feature-card {
            background: white;
            border-radius: 8px;
            padding: 25px;
            margin-bottom: 30px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
            transition: all 0.3s ease;
            height: 100%;
        }
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        }
        .feature-icon {
            font-size: 40px;
            margin-bottom: 20px;
            color: #3498db;
        }
        .feature-card h3 {
            margin-bottom: 15px;
            font-weight: 600;
            color: #2c3e50;
        }
        .feature-card p {
            color: #666;
            line-height: 1.6;
        }
        .cta-button {
            padding: 10px 25px;
            font-size: 15px;
            font-weight: 500;
            border-radius: 4px;
            margin-top: 10px;
            transition: all 0.3s ease;
        }
        
        /* 修复主内容区域样式 */
        .main-content {
            display: block !important;
            width: calc(100% - 240px);
            padding: 0 !important;
        }
        
        .content-wrapper {
            padding: 20px;
            width: 100%;
        }
        
        .panel {
            background: white;
            border-radius: 8px;
            margin-bottom: 30px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        }
        
        .panel-heading {
            padding: 15px 20px;
            background-color: #f5f7fa;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            border-bottom: 1px solid #e6e9ed;
        }
        
        .panel-title {
            margin: 0;
            font-size: 18px;
            font-weight: 600;
            color: #2c3e50;
        }
        
        .panel-body {
            padding: 20px;
        }
        
        @media (max-width: 768px) {
            .main-content {
                width: calc(100% - 70px);
            }
        }
    </style>
</head>
<body>
<div th:replace="include/TeacherNav :: TeacherNav"></div>

<script th:inline="javascript">
    $(document).ready(function() {
        // 确保内容区域被正确清空
        $(".main-content").empty();
        
        // 获取教师名字
        var teacherName = /*[[${session.Tlis != null ? session.Tlis.getTruename() : '老师'}]]*/ '老师';
        
        // 添加仪表盘内容到main-content区域
        renderDashboard();
        
        // 计算统计数据
        calculateStats();
    });
    
    function renderDashboard() {
        $(".main-content").append(`
            <div class="content-wrapper">
                <div class="container-fluid">
                    <!-- 欢迎卡片 -->
                    <div class="welcome-card">
                        <h2>欢迎使用在线考试系统</h2>
                        <p>本系统为教师提供全面的考试管理功能，包括学生管理、考试创建与管理、题库维护以及成绩分析等功能，帮助您高效开展教学工作。</p>
                        <a href="/addexam" class="btn btn-light cta-button">
                            <i class="glyphicon glyphicon-plus"></i> 创建新考试
                        </a>
                    </div>
                    
                    <!-- 统计卡片 -->
                    <div class="row">
                        <div class="col-md-3">
                            <div class="stats-card text-center">
                                <div class="stats-icon">
                                    <i class="glyphicon glyphicon-user"></i>
                                </div>
                                <div class="stats-number" id="studentCount">--</div>
                                <div class="stats-title">学生人数</div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="stats-card text-center">
                                <div class="stats-icon">
                                    <i class="glyphicon glyphicon-list-alt"></i>
                                </div>
                                <div class="stats-number" id="examCount">--</div>
                                <div class="stats-title">考试数量</div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="stats-card text-center">
                                <div class="stats-icon">
                                    <i class="glyphicon glyphicon-check"></i>
                                </div>
                                <div class="stats-number" id="subjectCount">--</div>
                                <div class="stats-title">题库题目</div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="stats-card text-center">
                                <div class="stats-icon">
                                    <i class="glyphicon glyphicon-stats"></i>
                                </div>
                                <div class="stats-number" id="passRate">--</div>
                                <div class="stats-title">平均通过率</div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 功能卡片 -->
                    <div class="row">
                        <div class="col-md-4">
                            <div class="feature-card text-center">
                                <div class="feature-icon">
                                    <i class="glyphicon glyphicon-user"></i>
                                </div>
                                <h3>学生管理</h3>
                                <p>管理班级学生信息，添加和编辑学生账号，查看学生考试情况。</p>
                                <a href="/StudentList" class="btn btn-primary cta-button">管理学生</a>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="feature-card text-center">
                                <div class="feature-icon">
                                    <i class="glyphicon glyphicon-list-alt"></i>
                                </div>
                                <h3>考试管理</h3>
                                <p>创建和管理考试，设置考试参数，查看考试进行情况。</p>
                                <a href="/selectexam" class="btn btn-primary cta-button">查看考试</a>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="feature-card text-center">
                                <div class="feature-icon">
                                    <i class="glyphicon glyphicon-stats"></i>
                                </div>
                                <h3>成绩分析</h3>
                                <p>查看学生考试成绩，分析班级整体表现，生成成绩报告。</p>
                                <a href="/findAllScore" class="btn btn-primary cta-button">查看成绩</a>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 系统介绍面板 -->
                    <div class="panel">
                        <div class="panel-heading">
                            <h3 class="panel-title">系统介绍</h3>
                        </div>
                        <div class="panel-body">
                            <p>在线考试系统，是为解决传统考试流程繁琐、效率低下等问题而生的数字化考试平台。聚焦考试全流程管理，覆盖从组卷、考务安排到在线答题、自动阅卷等环节，助力学校、企业等轻松实现标准化、高效化的考试组织与管理。</p>
                            <p>对于教育场景，它打破时空限制，支持随堂小测、期中期末考等多样化考试形式，教师可快速创建试卷、精准把控考试进度，还能借助系统数据分析，深入了解学生知识掌握情况；让考试从"负担"变为高效管理与人才发展的"助推器"，用科技重塑考试体验，让每一场考试都更简单、更智能。</p>
                        </div>
                    </div>
                </div>
            </div>
        `);
    }
    
    function calculateStats() {
        // 学生人数统计
        $.ajax({
            url: '/StudentList',
            type: 'GET',
            success: function(data) {
                // 解析返回的HTML页面，提取学生数量
                var studentCount = $(data).find('.pagination').text().match(/共\s+(\d+)\s+条记录/);
                if (studentCount && studentCount[1]) {
                    $('#studentCount').text(studentCount[1]);
                } else {
                    $('#studentCount').text('0');
                }
            },
            error: function() {
                $('#studentCount').text('0');
            }
        });
        
        // 考试数量统计
        $.ajax({
            url: '/selectexam',
            type: 'GET',
            success: function(data) {
                // 解析返回的HTML页面，提取考试数量
                var examCount = $(data).find('.pagination').text().match(/共\s+(\d+)\s+条记录/);
                if (examCount && examCount[1]) {
                    $('#examCount').text(examCount[1]);
                } else {
                    $('#examCount').text('0');
                }
            },
            error: function() {
                $('#examCount').text('0');
            }
        });
        
        // 题库题目统计
        $.ajax({
            url: '/finddanxuan',
            type: 'GET',
            success: function(data) {
                // 解析返回的HTML页面，提取单选题数量
                var singleCount = $(data).find('.pagination').text().match(/共\s+(\d+)\s+条记录/);
                var singleTotal = singleCount && singleCount[1] ? parseInt(singleCount[1]) : 0;
                
                // 获取多选题数量
                $.ajax({
                    url: '/findMultiple',
                    type: 'GET',
                    success: function(data2) {
                        var multipleCount = $(data2).find('.pagination').text().match(/共\s+(\d+)\s+条记录/);
                        var multipleTotal = multipleCount && multipleCount[1] ? parseInt(multipleCount[1]) : 0;
                        
                        // 显示总数
                        $('#subjectCount').text(singleTotal + multipleTotal);
                    },
                    error: function() {
                        $('#subjectCount').text(singleTotal);
                    }
                });
            },
            error: function() {
                $('#subjectCount').text('0');
            }
        });
        
        // 平均通过率统计
        $.ajax({
            url: '/findAllScore',
            type: 'GET',
            success: function(data) {
                // 解析返回的HTML页面，计算平均通过率
                var rows = $(data).find('table tbody tr');
                var passCount = 0;
                var totalCount = rows.length;
                
                if (totalCount > 0) {
                    rows.each(function() {
                        var scoreText = $(this).find('td:eq(4)').text();
                        var score = parseInt(scoreText);
                        if (score >= 60) {
                            passCount++;
                        }
                    });
                    
                    var passRate = Math.round((passCount / totalCount) * 100);
                    $('#passRate').text(passRate + '%');
                } else {
                    $('#passRate').text('0%');
                }
            },
            error: function() {
                $('#passRate').text('0%');
            }
        });
    }
</script>
</body>
</html>